package com.example.a33mvvm.register;

import androidx.lifecycle.MutableLiveData;

import com.example.base_mvvm.base.BaseRepo;
import com.example.base_mvvm.entity.RegisterEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

public class RegisterRepo extends BaseRepo {
    public void register(RequestBody body, MutableLiveData<RegisterEntity> success,MutableLiveData<String> failure){
        apiService.register(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<RegisterEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(RegisterEntity registerEntity) {
                        success.setValue(registerEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failure.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
